package org.jeecg.modules.santu;

import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.demo.wechat.pojo.QueueMessage;
import org.jeecg.modules.santu.service.ITbGroupMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RobotHelper {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private ITbGroupMemberService tbGroupMemberService;

    public void handlerGroupTextMsg(QueueMessage queueMessage) {
        String roomId = queueMessage.getRoomId();
        String wxid = queueMessage.getWxid();
        String content = queueMessage.getContent();
        System.out.println("roomId-------->"+roomId);
        System.out.println("wxid-------->"+wxid);
        System.out.println("content-------->"+content);
        if(content.startsWith("绑定")){

            String code = content.substring(2, content.length());
            System.out.println("code------>"+code);

            Object o = redisUtil.get(code);
            if(o !=null){
                System.out.println("更新数据------->");
                //发送绑定成功
                boolean b = tbGroupMemberService.bangdingBusiness(roomId, wxid, o.toString());
                if(b){
                    tbGroupMemberService.sendGroupTextMessage(roomId,wxid,"恭喜你绑定成功！");
                }else{
                    tbGroupMemberService.sendGroupTextMessage(roomId,wxid,"绑定失败！");
                }
            }else{
                tbGroupMemberService.sendGroupTextMessage(roomId,wxid,"绑定失败！");
            }
            System.out.println("处理绑定业务------->"+o);
        }


    }
}
